package com.ask.example.domain;

import java.util.Date;

import org.joda.time.Period;

public abstract class Person {

    protected final String name;
    protected Date dateOfBirth;

    public Person(String name) {
	this.name = name;
    }

    public final String getName() {
	return name;
    }

    public final Date getDateOfBirth() {
	return dateOfBirth;
    }

    public final void setDateOfBirth(Date dateOfBirth) {
	this.dateOfBirth = dateOfBirth;
    }

    public final int age() {
	if (dateOfBirth == null) {
	    throw new IllegalStateException("Date of birth not known for this person :" + this);
	}
	return new Period(new Date().getTime(), dateOfBirth.getTime()).getYears();
    }
}
